package apps.softtech.fastmarket.adapter;

import java.util.ArrayList;

import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import apps.softtech.fastmarket.R;
import apps.softtech.fastmarket.model.Product;

public class AdapterSearchMyProduct extends BaseAdapter{

	ArrayList<Product> mProductsList = new ArrayList<Product>();
	LayoutInflater inf;
	Context mContext;
	DisplayImageOptions options;
	
	public AdapterSearchMyProduct(Context mContext, ArrayList<Product> mProductsList,DisplayImageOptions options ){
		this.mContext = mContext;
		this.mProductsList = mProductsList;
		this.options = options;
		inf = (LayoutInflater)mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	}
	@Override
	public int getCount() {
		return mProductsList.size();
	}
	@Override
	public Object getItem(int arg0) {
		return null;
	}
	@Override
	public long getItemId(int arg0) {
		return 0;
	}

	@Override
	public View getView(int position, View vi, ViewGroup arg2) {
		if(mProductsList.size()==0||mProductsList==null){
			vi = inf.inflate(R.layout.search_no_result, null);
			return vi;
		}
		ViewHolder vh=null;
		if(vi==null){
			vi = inf.inflate(R.layout.item_product_list, null);
			vh = new ViewHolder();
			vh.ivProduct = (ImageView)vi.findViewById(R.id.ivProductList);
			vh.tvProductYour = (TextView) vi.findViewById(R.id.tvProductName);
			vi.setTag(vh);
		}
		else{
			vh = (ViewHolder) vi.getTag();
		}
		vh.tvProductYour.setText(""+mProductsList.get(position).getPrice());
	
		String url = mProductsList.get(position).getAvatarPath();
		ImageLoader.getInstance().displayImage(url, vh.ivProduct, options);
		return vi;
	}
	class ViewHolder{
		ImageView ivProduct;
		TextView tvProductYour;
	}

}
